Trouble setting current object

Hi all,

DXL newbie here. I've yet to have success with what seems to be a very basic functionality -- selecting the current object. I'm trying to gain familiarity by running some simple scripts such as the following:
 

Object o = current
string objectIdentifier = identifier(o)
string objectNumber = number(o)
int objectLevel = level(o)
 
print "Object \"" objectIdentifier "\" is at level " objectLevel " \n"
print "Its relative position is " objectNumber "\n"

 


I have a formal module open and an object selected (single click), but when I run this script I get the following:

 

 

 

-R-E- DXL: <Line:2> null Object parameter was passed into argument position 1
-I- DXL: execution halted



I know I'm missing something simple. Can someone out there please clue me in? Thanks!



 

 


SystemAdmin - Fri Oct 22 13:37:32 EDT 2010

Re: Trouble setting current object
llandale - Fri Oct 22 14:53:38 EDT 2010

The notion of 'current' is complex and is tied to the opening of modules and the context of the DXL. In your case, I suspect that you opened the module but then opened the DXL window from the DOORS explorer, in which case the DXL context is 'Folder' and it doesn't know anything about your open module.

Add this to the top of your code:

Module mCurr = current()
if (null mCurr) //
then print "no current module\n"
else print "current module: '" (name(mCurr)) "\t" (fullName(mCurr)) "\n"


I suspect you have no current module.

Also, when getting the current Object you should probably want to get it from a specific module:

 

o = current(mCurr)


Note that scripts that must run from an open module should routinely have something like this at the top:

 

 

Module    g_mOriginal = current()
if (null g_mOriginal            or
    type(g_mOriginal) "" != "Formal")       
   {errorBox("Run from open Formal module."); halt}       // ** HALT


Later in the code, when you MUST have a current module or object, you can do one of these:

 

 

current = g_mOriginal
   or
o = current(g_mOriginal)


that first one is a must when you use functions that presume the current module, such as many attribute commands (find, create etc). However, you may need to reset the current module aftwards, in which case your code may look like this:

 

 

Module mCurr = current
current = g_mOriginal
... do commands presume current module
if (!null mCurr) mCurr = current



When you want to SET a current Object, you will first need to set its module:



 

 

current = g_mOriginal
current = o



Yup, its all in the manual!! lol. Well, its all in Alphebet soup also.



 

 

 

  • Louie

 

 

Re: Trouble setting current object
SystemAdmin - Fri Oct 22 15:03:09 EDT 2010

llandale - Fri Oct 22 14:53:38 EDT 2010

The notion of 'current' is complex and is tied to the opening of modules and the context of the DXL. In your case, I suspect that you opened the module but then opened the DXL window from the DOORS explorer, in which case the DXL context is 'Folder' and it doesn't know anything about your open module.

Add this to the top of your code:

Module mCurr = current()
if (null mCurr) //
then print "no current module\n"
else print "current module: '" (name(mCurr)) "\t" (fullName(mCurr)) "\n"


I suspect you have no current module.

Also, when getting the current Object you should probably want to get it from a specific module:

 

o = current(mCurr)


Note that scripts that must run from an open module should routinely have something like this at the top:

 

 

Module    g_mOriginal = current()
if (null g_mOriginal            or
    type(g_mOriginal) "" != "Formal")       
   {errorBox("Run from open Formal module."); halt}       // ** HALT


Later in the code, when you MUST have a current module or object, you can do one of these:

 

 

current = g_mOriginal
   or
o = current(g_mOriginal)


that first one is a must when you use functions that presume the current module, such as many attribute commands (find, create etc). However, you may need to reset the current module aftwards, in which case your code may look like this:

 

 

Module mCurr = current
current = g_mOriginal
... do commands presume current module
if (!null mCurr) mCurr = current



When you want to SET a current Object, you will first need to set its module:



 

 

current = g_mOriginal
current = o



Yup, its all in the manual!! lol. Well, its all in Alphebet soup also.



 

 

 

  • Louie

 

 

Thanks Louie, that's immeasurably helpful. My current problem is solved, and I have somewhere to look when things get confusing in the future, too. I really appreciate the pointers.

All in alphabet soup indeed -- I guess next time I'll just have to open a few more cans!